const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    lists:[],
    type:2,
    isloading:true
  },
  onShow: function (options) {
    this.lists()
  },
  change(e){
    this.setData({
      type:e.currentTarget.dataset.index,
      lists:[],
    })
    this.lists()
  },
  lists(source){
    var data={
      type:1,
      contentType:this.data.type
    }
    Controller.LikeOrVisitList(data).then(res=>{
      if(res.data.baseData && res.data.baseData.list.length>0){
        this.setData({
          lists:res.data.baseData.list,
        })
      }
      this.setData({
        isloading:false
      })
    })
  },
  golink(e){
    var item=e.currentTarget.dataset.item;
    if(this.data.type==1){
      wx.navigateTo({
        url:"/pages/news/detail?id="+item.contentId
      });
    }else if(this.data.type==2){
      if(item.lessonId){
        wx.navigateTo({
          url:"/pages/videoDetails/videoDetails?id="+item.id
        });
      }else{
        wx.navigateTo({
          url:"/pages/news/detail?id="+item.contentId
        });
      }
    }else if(this.data.type==3){
      wx.navigateTo({
        url:"/pages/recipesDetails/recipesDetails?id="+item.contentId
      });
    }
    
  },
  onShareAppMessage: function (e) {
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
  onShareTimeline: function(res){
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
})